package file;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.net.Socket;

//import javax.xml.soap.Text;

public class FileServerThread extends Thread{

	Socket s;
	FileServer fs;

	long filesize;
	
	public FileServerThread(Socket s,FileServer fs){
		this.s=s;
		this.fs=fs;
		
				
		start();
	
	}
	
	
	public void run(){
		try{
			fs.textArea.append("서버스레드 시작\n");
			int n =10;
			int tempsize = 0;
			byte[] b = new byte[1024];
			
			File f = new File(fs.path);
			filesize =f.length();
			
			DataOutputStream dos = new DataOutputStream(s.getOutputStream());
			dos.writeUTF(f.getName());
			
			FileInputStream fis = new FileInputStream(fs.path);
			fs.textArea.append(fs.path);
			fs.textArea.append("전송 시작 \n");
			while((n=fis.read(b)) != -1){
				dos.write(b, 0, n);
			}
			fs.textArea.append("끝!!!!!!!!!\n");
			fis.close();
			dos.close();
			s.close();
			
		
		}catch(Exception e){
			
		}
	}
}
